package com.service.socket.ws.entity;


import com.alibaba.fastjson.JSON;
import com.service.socket.common.entity.SendMessageVo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.websocket.Session;
import java.io.IOException;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WebSocketSender {

    private String id;

    private Session session;

    private String channel;

    public void sendData(SendMessageVo sendMessageVo) {
        if(session.isOpen()){
            try {
                session.getBasicRemote().sendText(JSON.toJSONString(sendMessageVo));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
